// component/zy-modal/zy-modal.js
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
  },
  /**
   * 组件的初始数据
   */
  data: {
    hidden: true,
    showData: {
      topImageUrl: '', //顶部图片地址
      modalType: 0, //0 弹窗提示   1 输入弹窗  2数字密码输入   3 选择弹框搭配contentList  4、多选 搭配contentMoreList 进行选择
      title: '', //标题
      content: '', //内容
      contentList: [], //可以分列
      contentMoreList: [], // [{name:'',isSelect:true}] 
      selectContentIndex: 0,
      placeholderText: '', //输入提示 
      inputValue: '', //输入值
      inputList: [{ //输入框list
        placeholderText: '',
        inputValue: '',
        keyboardType: 'text'
      }],
      hideCancelBtn: false,
      hideConfirmBtn: false,
      confirmText: '确认',
      cancelText: '取消',
      confirmColor: 'color:#00a48f',
      editable: true,
      complete: (res) => {},
    },
    showData: {},
    chooseContentMoreList: [],
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getInput(e) {
      let index = e.currentTarget.dataset.index;
      this.data.showData.inputList[index].inputValue = e.detail.value;
    },
    cancel: function () {
      this.returnData(false)
    },
    confirm: function () {
      this.returnData(true)
    },
    returnData(temp) {
      let res = {}
      if (temp) {
        res.confirm = true
        res.data = this.data
        let contentMoreList = res.data.showData.contentMoreList;
        if (contentMoreList && contentMoreList.length) {
          let muList = []
          for (let i = 0; i < contentMoreList.length; i++) {
            let item = contentMoreList[i];
            if (item.isSelect) {
              muList.push(item)
            }
          }
          res.data.chooseContentMoreList = muList
        }
      } else {
        res.cancel = true
      }
      this.data.showData.complete(res)
      this.setData({
        hidden: true,
      })
    },
    didClickContent(e) {
      if (this.data.showData.modalType == 3) {
        var showData = this.data.showData
        showData.selectContentIndex = e.currentTarget.dataset.id
        this.setData({
          showData: showData
        })
      }
    },
    didClickSelectMore(e) { //多选
      let index = e.currentTarget.dataset.id;
      var showData = this.data.showData
      showData.contentMoreList[index].isSelect = showData.contentMoreList[index].isSelect ? false : true
      this.setData({
        showData: showData
      })
    },
    showModal(data) {
      let dt = data;
      dt.modalType = data.modalType ? data.modalType : 0;
      dt.topImageUrl = data.topImageUrl ? data.topImageUrl : '';
      dt.selectContentIndex = data.selectContentIndex ? data.selectContentIndex : 0;
      dt.inputValue = data.inputValue || ''
      dt.inputList = data.inputList || []
      if (data.contentMoreList) {
        let muList = [];
        for (let i = 0; i < data.contentMoreList.length; i++) {
          let item = data.contentMoreList[i];
          item.isSelect = true;
          muList.push(item)
        }
        dt.contentMoreList = muList || []
      }
      this.setData({
        chooseContentMoreList: dt.contentMoreList,
        showData: dt,
        hidden: false
      })
    }
  },
  ready: function () {
  }
})